<?php
/**
 * Created by PhpStorm.
 * User: yys
 * Date: 2017/1/10
 * Time: 22:44
 * 采购单后台
 */

namespace App\Http\Controllers\Backstage;
use App\Http\Controllers\Controller;
use App\Services\BrandService\BrandToolService;
use App\Services\ProductTempService\ProductTempTool;
use App\Services\PurchaseOrderService\PurchaseOrderBackService;
use Illuminate\Http\Request;
use App\Services\SupplierService\SupplierTool;
use App\Services\Tool\ExpressTool;
use Illuminate\Support\Facades\Log;

class PurchaseOrderController extends Controller
{
    private $purchaseOrderBackSer;
    private $supplierTool;
    private $productTempTool;
    /**
     * PurchaseOrderController constructor.
     */
    public function __construct(PurchaseOrderBackService $purchaseOrderBackSer,
                                ProductTempTool $productTempTool,
                                SupplierTool $supplierTool)
    {
        $this->purchaseOrderBackSer=$purchaseOrderBackSer;
        $this->supplierTool=$supplierTool;
        $this->productTempTool=$productTempTool;
    }

    /***
     * 添加订购单页面
     * @param Request $request
     * @return $this
     */
    public function addPurchaseOrderPage(Request $request)
    {
        $suppliers=SupplierTool::getAllSupplier();
        $express = ExpressTool::get_express_list();
        return view('backstage.purchaseOrder.addPurchaseOrder')
            ->with('suppliers',$suppliers)
            ->with('express_list',$express);
    }

    /***
     * 订货单列表页面
     * @param Request $request
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function purchaseOrderListPage(Request $request)
    {
        $page=intval($request->input('page'));
        $status=intval($request->input('status'));
        $supplier_id=intval($request->input('supplier_id'));
        if(!empty($page)&&(!is_int($page)||($page>100))){
            return redirect()->back()->with('error_message','暂无数据');
        }
        $condition=array();
        $condition['status']=empty($status)?0:$status;
        $condition['supplier_id']=empty($supplier_id)?0:$supplier_id;
        $purchase_orders=$this->purchaseOrderBackSer->getPurchaseOrderList($condition);
        if($purchase_orders===false){
            return redirect()->back()->with('error_message','系统繁忙，请稍后再试！');
        }
        $suppliers=SupplierTool::getAllSupplier();
        return view('backstage.purchaseOrder.purchaseOrderList')
            ->with('purchase_orders',$purchase_orders)
            ->with('supplier_id',$supplier_id)
            ->with('suppliers',$suppliers)
            ->with('purchase_order_status',$status);
    }

    /***
     * 更新订货单状态
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updateStatus(Request $request){
        $rule=array(
            'purchase_order_status'=>'required|integer|min:0|max:4',
            'id'=>'required|integer|',
        );
        $validator=PurchaseOrderBackService::store($request,$rule);
        $purchase_order_status=intval($request->input('purchase_order_status'));
        $id=intval($request->input('id'));
        if ($validator->fails())
        {
            if($validator->errors()->first('id')){
                $result['message']='id格式错误';
            }elseif($validator->errors()->first('purchase_order_status')){
                $result['message']='请重新选择状态';
            }
            $result['state']=-2;
            return response()->json($result);
        }
        $purchase_order=$this->purchaseOrderBackSer->getPurchaseOrderById($id);
        if(empty($purchase_order)){
            $result['message']='订货单不存在';
            $result['state']=-3;
            return response()->json($result);
        }elseif ($purchase_order->purchase_order_status==4){
            $result['message']='订货单已入库不允许修改';
            $result['state']=-4;
            return response()->json($result);
        }
        $purchase_order_arr['purchase_order_status']=$purchase_order_status;
        $purchase_order_arr['purchase_order_id']=$id;
        $update_status_res=$this->purchaseOrderBackSer->updatePurchaseOrderToDB($purchase_order_arr);
        if($update_status_res){
            $result['message']='更新成功';
            $result['state']=1;
            if($purchase_order_status==4){
                $purchase_order_details=$this->purchaseOrderBackSer->getPurchaseOrderDetailByPurchaseOrderId($id);
                foreach ($purchase_order_details as $purchase_order_detail){
                    $this->purchaseOrderBackSer->updateTempActualStock($purchase_order_detail->sku,$purchase_order_detail->num);
                }
            }
        }else{
            $result['message']='更新失败';
            $result['state']=-1;
        }
        return response()->json($result);
    }

    /***
     * 删除订货单
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delPurchaseOrder(Request $request){
        $rule=array(
            'id'=>'required|integer|',
        );
        $validator=PurchaseOrderBackService::store($request,$rule);
        $id=intval($request->input('id'));
        if ($validator->fails())
        {
            if($validator->errors()->first('id')){
                $result['message']='id格式错误';
            }
            $result['state']=-2;
            return response()->json($result);
        }
        $purchase_order_exist=$this->purchaseOrderBackSer->purchaseOrderExistById($id);
        if(!$purchase_order_exist){
            $result['message']='订货单不存在';
            $result['state']=-3;
            return response()->json($result);
        }
        $purchase_order['purchase_order_id']=$id;
        $purchase_order['state']=0;
        $update_status_res=$this->purchaseOrderBackSer->updatePurchaseOrderToDB($purchase_order);
        $del=$this->purchaseOrderBackSer->delPurchaseOrderDetailByPurchaseOrderId($id);
        if($update_status_res){
            $result['message']='更新成功';
            $result['state']=1;
        }else{
            $result['message']='更新失败';
            $result['state']=-1;
        }
        return response()->json($result);
    }

    /***
     * 删除订货单绑定下的sku
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function delPurchaseOrderMapBySku(Request $request){
        $rule=array(
            'purchase_order_id'=>'required|integer|',
            'sku'=>'required|string|min:13|max:13',
        );
        $validator=PurchaseOrderBackService::store($request,$rule);
        $purchase_order_id=intval($request->input('purchase_order_id'));
        $sku=trim($request->input('sku'));
        if ($validator->fails())
        {
            if($validator->errors()->first('purchase_order_id')){
                $result['message']='订货单编号格式错误';
                $result['state']=-2;
            }elseif ($validator->errors()->first('sku')){
                $result['message']='sku格式错误';
                $result['state']=-3;
            }
            if(isset($result)&&!empty($result)){
                return response()->json($result);
            }
        }
        $purchase_order_exist=$this->purchaseOrderBackSer->purchaseOrderDetailExistByPurchaseOrderIdAndSku($purchase_order_id,$sku,1);
        if(!$purchase_order_exist){
            $result['message']='数据不存在';
            $result['state']=-3;
            return response()->json($result);
        }
        $purchase_order=$this->purchaseOrderBackSer->getPurchaseOrderById($purchase_order_id);
        if($purchase_order->purchase_order_status!==1){
            $result['message']='已下单后，明细不允许删除';
            $result['state']=-1;
            return response()->json($result);
        }
        $del_res=$this->purchaseOrderBackSer->delPurchaseOrderDetailByPurchaseOrderIdAndSku($purchase_order_id,$sku);
        if($del_res){
            $result['message']='删除成功';
            $result['state']=1;
        }else{
            $result['message']='删除失败';
            $result['state']=-1;
        }
        return response()->json($result);
    }

    /***
     * 添加订货详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addPurchaseOrderMap(Request $request){
        $rule=array(
            'purchase_order_id'=>'required|integer|',
            'num'=>'required|integer|min:0',
            'actual_fee'=>'required|numeric|min:0',
            'price'=>'required|numeric|min:0',
            'sku'=>'required|string|min:13|max:13',
        );
        $validator=PurchaseOrderBackService::store($request,$rule);
        $purchase_order_id=intval($request->input('purchase_order_id'));
        $num=intval($request->input('num'));
        $actual_fee=floatval($request->input('actual_fee'));
        $price=floatval($request->input('price'));
        $sku=trim($request->input('sku'));
        $data['purchase_order_id']=$purchase_order_id;
        $data['num']=$num;
        $data['actual_fee']=$actual_fee;
        $data['price']=$price;
        $data['sku']=$sku;
        if ($validator->fails())
        {
            if($validator->errors()->first('purchase_order_id')){
                $result['message']='订货单编号格式错误';
                $result['state']=-2;
            }elseif ($validator->errors()->first('sku')){
                $result['message']='sku格式错误';
                $result['state']=-3;
            }elseif ($validator->errors()->first('num')){
                $result['message']='数量格式错误';
                $result['state']=-4;
            }elseif ($validator->errors()->first('actual_fee')){
                $result['message']='实际支付格式错误';
                $result['state']=-5;
            }elseif ($validator->errors()->first('price')){
                $result['message']='单价格式错误';
                $result['state']=-5;
            }
            if(isset($result)&&!empty($result)){
                return response()->json($result);
            }
        }
        $purchase_order=$this->purchaseOrderBackSer->getPurchaseOrderById($purchase_order_id);
        if(empty($purchase_order)){
            $result['message']='订货单不存在';
            $result['state']=-3;
            return response()->json($result);
        }elseif($purchase_order->purchase_order_status!==1){
            $result['message']='已下单后，明细不允许添加';
            $result['state']=-1;
            return response()->json($result);
        }
        $product_temp_stock =  $this->productTempTool->getProductTempStockBySku($sku,1);
        if(empty($product_temp_stock)){
            $result['state']=-1;
            $result['message']='sku对应模板信息不存在';
            return response()->json($result);
        }
        $data['colour_id']=$product_temp_stock->colour_id;
        $data['colour_name']=$product_temp_stock->colour_name;
        $data['size_name']=$product_temp_stock->size_name;
        $data['product_temp_id']=$product_temp_stock->product_temp_id;
        $add_res=$this->purchaseOrderBackSer->addPurchaseOrderDetail($data);
        if($add_res){
            $result['message']='添加成功';
            $result['state']=1;
        }else{
            $result['message']='添加失败';
            $result['state']=-1;
        }
        return response()->json($result);
    }
    /***
     * 订货单详情页面
     * @param Request $request
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function purchaseOrderDetail(Request $request){
        $rule=array(
            'id'=>'required|integer|',
        );
        $validator=PurchaseOrderBackService::store($request,$rule);
        $id=intval($request->input('id'));
        if ($validator->fails())
        {
            if($validator->errors()->first('id')){
                return redirect()->back()->with('error_message','id格式错误');
            }
        }
        $purchase_order=$this->purchaseOrderBackSer->getPurchaseOrderById($id);
        if(empty($purchase_order)){
            return redirect()->back()->with('error_message','订货单不存在');
        }
        $purchase_order_details=$this->purchaseOrderBackSer->getPurchaseOrderDetailByPurchaseOrderId($id);
        foreach ($purchase_order_details as $purchase_order_detail){
            $brand_id=ProductTempTool::getBrandIdByProdTempId($purchase_order_detail->product_temp_id);
            $temp_name=$this->productTempTool->getProductTempNameByProductTempId($purchase_order_detail->product_temp_id,1);
            $brand_name='';
            if(!empty($brand_id)){
                $brand_name=BrandToolService::getBrandNameByBrandId($brand_id);
            }
            $purchase_order_detail->brand_name=$brand_name;
            $purchase_order_detail->brand_id=$brand_id;
            $purchase_order_detail->temp_name=$temp_name;
        }
        $express = ExpressTool::get_express_list();
        return view('backstage.purchaseOrder.purchaseOrderDetail')
            ->with('purchase_order_details',$purchase_order_details)
            ->with('purchase_order',$purchase_order)
            ->with('express_list',$express);
    }

    /***
     * 订货单更新页面
     * @param Request $request
     * @return $this|\Illuminate\Http\RedirectResponse
     */
    public function updatePurchaseOrderPage(Request $request){
        $rule=array(
            'id'=>'required|integer|',
        );
        $validator=PurchaseOrderBackService::store($request,$rule);
        $id=intval($request->input('id'));
        if ($validator->fails())
        {
            if($validator->errors()->first('id')){
                return redirect()->back()->with('error_message','id格式错误');
            }
        }
        $purchase_order=$this->purchaseOrderBackSer->getPurchaseOrderById($id);
        if(empty($purchase_order)){
            return redirect()->back()->with('error_message','订货单不存在');
        }
        $purchase_order_details=$this->purchaseOrderBackSer->getPurchaseOrderDetailByPurchaseOrderId($id);
        foreach ($purchase_order_details as $purchase_order_detail){
            $brand_id=ProductTempTool::getBrandIdByProdTempId($purchase_order_detail->product_temp_id);
            $temp_name=$this->productTempTool->getProductTempNameByProductTempId($purchase_order_detail->product_temp_id,1);
            $brand_name='';
            if(!empty($brand_id)){
                $brand_name=BrandToolService::getBrandNameByBrandId($brand_id);
            }
            $purchase_order_detail->brand_name=$brand_name;
            $purchase_order_detail->brand_id=$brand_id;
            $purchase_order_detail->temp_name=$temp_name;
        }
        $product_temp_ids=SupplierTool::getTempBySupplierID($purchase_order->supplier_id);
        $product_temps=array();
        if(!empty($product_temp_ids)){
            $product_temps=$this->productTempTool->getProductTempsWhereInProductTempIds($product_temp_ids);
        }
        $express = ExpressTool::get_express_list();
        return view('backstage.purchaseOrder.updatePurchaseOrder')
            ->with('purchase_order_details',$purchase_order_details)
            ->with('express_list',$express)
            ->with('product_temps',$product_temps)
            ->with('purchase_order',$purchase_order);
    }
    /***
     * 保存订货单
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function save(Request $request){
        $rule=array(
            'supplier_id'=>'required|integer|min:1',
            'actual_fee'=>'required|numeric|min:0',
            'postage'=>'required|numeric|min:0',
            'order_express_id'=>'required|string|min:1',
            'express_id'=>'required|string|min:1',
        );
        $supplier_id=intval($request->input('supplier_id'));
        $actual_fee=floatval($request->input('actual_fee'));
        $postage=floatval($request->input('postage'));
        $order_express_id=trim($request->input('order_express_id'));
        $express_id=trim($request->input('express_id'));
        $remark=trim($request->input('remark'));
        $product_temp_skus=$request->input('product_temp_skus');
        $data['supplier_id']=$supplier_id;
        $data['actual_fee']=$actual_fee;
        $data['postage']=$postage;
        $data['order_express_id']=$order_express_id;
        $data['express_id']=$express_id;
        $data['product_temp_skus']=$product_temp_skus;
        $data['remark']=empty($remark)?'':$remark;
        $validator=PurchaseOrderBackService::store($request,$rule);
        if ($validator->fails())
        {
            if($validator->errors()->first('supplier_id')){
                $result['state']=-2;
                $result['message']='供应商编号格式错误';
            }elseif($validator->errors()->first('actual_fee')){
                $result['state']=-3;
                $result['message']='邮费格式错误';
            }elseif($validator->errors()->first('postage')){
                $result['state']=-4;
                $result['message']='格式错误';
            }elseif($validator->errors()->first('sku')){
                $result['state']=-5;
                $result['message']='sku格式错误';
            }elseif($validator->errors()->first('order_express_id')){
                $result['state']=-6;
                $result['message']='快递单号格式错误';
            }elseif($validator->errors()->first('express_id')){
                $result['state']=-7;
                $result['message']='快递公司格式错误';
            }
            if(isset($result)&&!empty($result)){
                return response()->json($result);
            }
        }
        if(empty($product_temp_skus)){
            $result['state']=-8;
            $result['message']='订货明细为空！';
            return response()->json($result);
        }elseif (!is_array($product_temp_skus)){
            $result['state']=-9;
            $result['message']='订货明细格式错误！';
            return response()->json($result);
        }
        $supplier_exist=SupplierTool::isExistBySupplierID($supplier_id);
        if(!$supplier_exist){
            $result['state']=-10;
            $result['message']='订货商不存在！';
            return response()->json($result);
        }
        foreach ($product_temp_skus as $product_temp_sku){
            $temp_sku_arr=explode('_',$product_temp_sku);
            $arr_size=count($temp_sku_arr);
            if($arr_size!=4){
                $result['state']=-9;
                $result['message']='订货明细格式错误！';
                break;
            }
            $sku=$temp_sku_arr[0];
            $sku_exist=$this->productTempTool->getProductTempSkuExistBySku($sku);
            if(!$sku_exist){
                $result['state']=-11;
                $result['message']='sku为'.$sku.',不存在';
                break;
            }
        }
        if(isset($result)&&!empty($result)){
            return response()->json($result);
        }
        $save_res=$this->purchaseOrderBackSer->save($data);
        if($save_res){
            $result['state']=1;
            $result['message']='成功';
        }else{
            $result['state']=-1;
            $result['message']='失败';
        }
        return response()->json($result);
    }

    /***
     * 订货单快递单号更新
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updatePurchaseOrderExpress(Request $request){
        $rule=array(
            'purchase_order_id'=>'required|integer|min:1',
            'order_express_id'=>'required|string|min:1',
            'express_id'=>'required|string|min:1',
        );
        $purchase_order_id=intval($request->input('purchase_order_id'));
        $order_express_id=trim($request->input('order_express_id'));
        $express_id=trim($request->input('express_id'));
        $data['purchase_order_id']=$purchase_order_id;
        $data['order_express_id']=$order_express_id;
        $data['express_id']=$express_id;
        $validator=PurchaseOrderBackService::store($request,$rule);
        if ($validator->fails())
        {
            if($validator->errors()->first('purchase_order_id')){
                $result['state']=-3;
                $result['message']='订货单编号错误';
            }elseif($validator->errors()->first('order_express_id')){
                $result['state']=-6;
                $result['message']='快递单号格式错误';
            }elseif($validator->errors()->first('express_id')){
                $result['state']=-7;
                $result['message']='快递公司格式错误';
            }
            if(isset($result)&&!empty($result)){
                return response()->json($result);
            }
        }
        $purchase_order_exist=$this->purchaseOrderBackSer->purchaseOrderExistById($purchase_order_id);
        if(!$purchase_order_exist){
            $result['message']='订货单不存在';
            $result['state']=-11;
            return response()->json($result);
        }
        $save_res=$this->purchaseOrderBackSer->updatePurchaseOrderToDB($data);
        if($save_res){
            $result['state']=1;
            $result['message']='成功';
        }else{
            $result['state']=-1;
            $result['message']='失败';
        }
        return response()->json($result);
    }

    /***
     * 订货单更新
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function updatePurchaseOrder(Request $request){
        $rule=array(
            'supplier_id'=>'required|integer|min:1',
            'purchase_order_id'=>'required|integer|min:1',
            'actual_fee'=>'required|numeric|min:0',
            'postage'=>'required|numeric|min:0',
            'order_express_id'=>'required|string|min:1',
            'express_id'=>'required|string|min:1',
        );
        $supplier_id=intval($request->input('supplier_id'));
        $purchase_order_id=intval($request->input('purchase_order_id'));
        $actual_fee=floatval($request->input('actual_fee'));
        $postage=floatval($request->input('postage'));
        $order_express_id=trim($request->input('order_express_id'));
        $express_id=trim($request->input('express_id'));
        $remark=trim($request->input('remark'));
        $data['purchase_order_id']=$purchase_order_id;
        $data['supplier_id']=$supplier_id;
        $data['actual_fee']=$actual_fee;
        $data['postage']=$postage;
        $data['order_express_id']=$order_express_id;
        $data['express_id']=$express_id;
        $data['remark']=$remark;
        $validator=PurchaseOrderBackService::store($request,$rule);
        if ($validator->fails())
        {
            if($validator->errors()->first('supplier_id')){
                $result['state']=-2;
                $result['message']='供应商编号格式错误';
            }elseif($validator->errors()->first('purchase_order_id')){
                $result['state']=-3;
                $result['message']='订货单编号错误';
            }elseif($validator->errors()->first('actual_fee')){
                $result['state']=-3;
                $result['message']='邮费格式错误';
            }elseif($validator->errors()->first('postage')){
                $result['state']=-4;
                $result['message']='格式错误';
            }elseif($validator->errors()->first('sku')){
                $result['state']=-5;
                $result['message']='sku格式错误';
            }elseif($validator->errors()->first('order_express_id')){
                $result['state']=-6;
                $result['message']='快递单号格式错误';
            }elseif($validator->errors()->first('express_id')){
                $result['state']=-7;
                $result['message']='快递公司格式错误';
            }
            if(isset($result)&&!empty($result)){
                return response()->json($result);
            }
        }
        $supplier_exist=SupplierTool::isExistBySupplierID($supplier_id);
        if(!$supplier_exist){
            $result['state']=-10;
            $result['message']='订货商不存在！';
            return response()->json($result);
        }
        $purchase_order=$this->purchaseOrderBackSer->getPurchaseOrderById($purchase_order_id);
        if(empty($purchase_order)){
            $result['message']='订货单不存在';
            $result['state']=-11;
            return response()->json($result);
        }
        $save_res=$this->purchaseOrderBackSer->updatePurchaseOrderToDB($data);
        if($save_res){
            $result['state']=1;
            $result['message']='成功';
        }else{
            $result['state']=-1;
            $result['message']='失败';
        }
        return response()->json($result);
    }
    /***
     * 按照订货商Id获取可提供的产品模板
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getTempsBySupplierId(Request $request)
    {
        $supplier_id=intval($request->input('supplier_id'));
        if(empty($supplier_id)){
            $result['state']=-2;
            $result['message']='编号格式错误';
            return response()->json($result);
        }
        $product_temp_ids=SupplierTool::getTempBySupplierID($supplier_id);
        $product_temps=array();
        if(!empty($product_temp_ids)){
            $product_temps=$this->productTempTool->getProductTempsWhereInProductTempIds($product_temp_ids);
        }
        $result['state']=1;
        $result['message']='成功';
        $result['data']=$product_temps;
        return response()->json($result);
    }

    /***
     * 导出供应商可提供的产品模板
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function exportExcel(Request $request)
    {
        $supplier_id=intval($request->input('supplier_id'));
        if(empty($supplier_id)){
            $result['state']=-2;
            $result['message']='编号格式错误';
            return response()->json($result);
        }
        $product_temp_ids=SupplierTool::getTempBySupplierID($supplier_id);
        $product_temps=array();
        if(!empty($product_temp_ids)){
            $get_xls_url=$this->purchaseOrderBackSer->exportExcelByProductTempIds($product_temp_ids);
        }
        if(isset($get_xls_url)&&!empty($get_xls_url)){
            $result['state']=1;
            $result['message']='成功';
            $result['xls_url']=$get_xls_url;
        }else{
            $result['state']=-1;
            $result['message']='数据为空';
            $result['xls_url']='';
        }
        return response()->json($result);
    }
    /***
     * sku和供货商id获取可提供的产品模板
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getTempStockBySku(Request $request)
    {
        $sku=trim($request->input('sku'));
        $supplier_id=intval($request->input('supplier_id'));
        if(empty($sku)){
            $result['state']=-2;
            $result['message']='sku为空';
            return response()->json($result);
        }elseif(empty($supplier_id)){
            $result['state']=-3;
            $result['message']='编号格式错误';
            return response()->json($result);
        }
        $product_temp_stock =  $this->productTempTool->getProductTempStockBySku($sku,1);
        if(empty($product_temp_stock)){
            $result['state']=-1;
            $result['message']='信息不存在';
            return response()->json($result);
        }
        $product_temp_id=$product_temp_stock->product_temp_id;
        $brand_id=ProductTempTool::getProdTempBrandIdByProdTempId($product_temp_id);
        $brand_name='';
        $temp_name=$this->productTempTool->getProductTempNameByProductTempId($product_temp_id);
        if(!empty($brand_id)){
            $brand_name=BrandToolService::getBrandNameByBrandId($brand_id);
        }
        $product_temp_stock->temp_name=$temp_name;
        $product_temp_stock->brand_id=$brand_id;
        $product_temp_stock->brand_name=$brand_name;
        $product_temp_ids=$this->supplierTool->getTempBySupplierID($supplier_id);
        if(empty($product_temp_ids)||!in_array($product_temp_id,$product_temp_ids)){
            $result['state']=-3;
            $result['message']='提供商不提供该模板';
        }else{
            $result['state']=1;
            $result['message']='成功';
            $result['temp_stock']=$product_temp_stock;
        }
        return response()->json($result);
    }
}